package avicit.bdp.dms.das.service;

import avicit.bdp.common.base.BaseService;
import avicit.bdp.dms.das.dao.BdpDasColumnViewSettingDao;
import avicit.bdp.dms.das.dto.BdpDasColumnViewSettingDTO;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.core.context.ThreadContextHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;


/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2023-09-06 14:54
 * @类说明：bdp_das_businesslinkService
 * @修改记录：
 */
@Service
public class BdpDasColumnViewSettingService extends BaseService<BdpDasColumnViewSettingDao, BdpDasColumnViewSettingDTO> {

    private static final Logger LOGGER = LoggerFactory.getLogger(BdpDasColumnViewSettingService.class);

    public String saveColumnSetting(BdpDasColumnViewSettingDTO viewSettingDTO) {
        BdpDasColumnViewSettingDTO query = new BdpDasColumnViewSettingDTO();
        query.setTableId(viewSettingDTO.getTableId());
        String userId = ThreadContextHelper.getUserId();
        if (StringUtils.isBlank(userId)) {
            userId = "1";
        }
        query.setCreatedBy(userId);
        BdpDasColumnViewSettingDTO oldView = this.selectOne(query);
        if (oldView != null) {
            oldView.setSettingJosn(viewSettingDTO.getSettingJosn());
            this.updateByPrimaryKey(oldView);
            return oldView.getId();
        } else {
            String id = ComUtil.getId();
            viewSettingDTO.setId(id);
            this.insert(viewSettingDTO);
            return id;
        }
    }

    public BdpDasColumnViewSettingDTO getColumnSetting(String tableId) {
        BdpDasColumnViewSettingDTO query = new BdpDasColumnViewSettingDTO();
        query.setTableId(tableId);
        String userId = ThreadContextHelper.getUserId();
        if (StringUtils.isBlank(userId)) {
            userId = "1";
        }
        query.setCreatedBy(userId);
        return this.selectOne(query);
    }
}